package com.qinggeng.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.project.system.domain.UserGoodsLimitRecord;
import com.qinggeng.project.system.service.IUserGoodsLimitRecordService;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.web.page.TableDataInfo;
/**
 * 用户商品限购记录Controller
 *
 * @author smallfish
 * @date 2020-12-05
 */
@RestController
@RequestMapping("/system/limit")
public class UserGoodsLimitRecordController extends BaseController
{
    @Autowired
    private IUserGoodsLimitRecordService userGoodsLimitRecordService;

    /**
     * 查询用户商品限购记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:limit:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserGoodsLimitRecord userGoodsLimitRecord)
    {
        startPage();
        List<UserGoodsLimitRecord> list = userGoodsLimitRecordService.listUserGoodsLimitRecord(userGoodsLimitRecord);
        return getDataTable(list);
    }

    /**
     * 导出用户商品限购记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:limit:export')")
    @Log(title = "用户商品限购记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserGoodsLimitRecord userGoodsLimitRecord)
    {
        List<UserGoodsLimitRecord> list = userGoodsLimitRecordService.listUserGoodsLimitRecord(userGoodsLimitRecord);
        ExcelUtil<UserGoodsLimitRecord> util = new ExcelUtil<UserGoodsLimitRecord>(UserGoodsLimitRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取用户商品限购记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:limit:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return AjaxResult.success(userGoodsLimitRecordService.getUserGoodsLimitRecordById(recordId));
    }

    /**
     * 新增用户商品限购记录
     */
    @PreAuthorize("@ss.hasPermi('system:limit:add')")
    @Log(title = "用户商品限购记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserGoodsLimitRecord userGoodsLimitRecord)
    {
        return toAjax(userGoodsLimitRecordService.insertUserGoodsLimitRecord(userGoodsLimitRecord));
    }

    /**
     * 修改用户商品限购记录
     */
    @PreAuthorize("@ss.hasPermi('system:limit:edit')")
    @Log(title = "用户商品限购记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserGoodsLimitRecord userGoodsLimitRecord)
    {
        return toAjax(userGoodsLimitRecordService.updateUserGoodsLimitRecord(userGoodsLimitRecord));
    }

    /**
     * 删除用户商品限购记录
     */
    @PreAuthorize("@ss.hasPermi('system:limit:remove')")
    @Log(title = "用户商品限购记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(userGoodsLimitRecordService.deleteUserGoodsLimitRecordByIds(recordIds));
    }
}
